<template xmlns="http://www.w3.org/1999/html">
  <sea-data-table ref="tableObject" url="/sys/role/page">
    <!--表头-->
    <sea-table-header slot="header">
      <!--标题栏-->
      <sea-table-title slot="title" title="角色管理">
        <sea-tips>
          <p>权限、菜单分配到角色，再通过角色分配到具体用户</p>
          <p>权限自上向下分配，无特权账号。</p>
        </sea-tips>
      </sea-table-title>

      <!--输入-->
      <template slot="input">
        <smart-form-layout require name="keyword" label="关键字" :span="6">
          <smart-text-view name="keyword" placeholder="keyword"></smart-text-view>
        </smart-form-layout>
      </template>

      <!--按钮栏-->
      <el-button slot="buttons" @click="onAction('new')">新建</el-button>
    </sea-table-header>

    <!-- 弹窗、抽屉 -->
    <template slot="drawer">
      <sea-dialog ref="create_dialog">
        <create ref="create"></create>
      </sea-dialog>
      <sea-dialog ref="modify_dialog">
        <modify ref="modify" :object="row_data"></modify>
      </sea-dialog>
    </template>

    <!--表头-->
    <template slot="columns">
      <el-table-column property="roleName" label="角色名称" width="180"></el-table-column>
      <el-table-column property="authorityCode" label="授权码" width="180"></el-table-column>
      <el-table-column property="description" label="角色描述" width="180" show-overflow-tooltip></el-table-column>
      <sea-col-switch property="isDisabled" label="是否可用" reverse></sea-col-switch>

      <!--操作栏-->
      <sea-table-actionbar width="180" :on-action="onAction" :buttons="buttons"></sea-table-actionbar>
    </template>
  </sea-data-table>
</template>

<script>
// import RolePanel from "./role-panel";
import create from "./create";
import modify from "./modify";

export default {
    components: {create, modify},
    data() {
        return {
            // 操作名称
            operation: undefined
            // 当前操作的行级对象
            , row_data: undefined
            // 操作栏
            , buttons: [
                {type: 'btn', evt: 'edit', label: '编辑', title: '编辑当前行'}
            ]
            // end--
        }
    },
    methods: {
        /**
         * 操作成功回调
         */
        onSucceed: function () {
            this.$refs.tableObject.reload();
            if (this.operation === 'new') {
                this.$refs.create_dialog.close();
            } else if (this.operation === 'edit') {
                this.$refs.modify_dialog.close();
            }
        },
        /**
         * 操作栏事件分发
         * @param evt 事件
         * @param row 行级对象
         * @param old 可供回滚的参数
         */
        onAction: function (evt, row, old) {
            this.operation = evt;
            if (evt === 'new') {
                let dialog = {title: `新建`, width: '50%'};
                this.$refs.create_dialog.open(dialog);
            } else if (evt === 'edit') {
                let dialog = {title: `更新`, width: '70%'};
                this.$refs.modify_dialog.open(dialog).then(() => {
                    this.row_data = row;
                });
            }
        }
    }
}
</script>
